var prefix = '/sys/menu/';
$(document).ready(function(){
    //页面加载完的初始化方法
    validateEditForm();
    //打开图标列表
    $("#ico-btn").click(function(){
        layer.open({
            type: 2,
            title:'图标列表',
            content: '/FontIcoList.html',
            area: ['480px', '90%'],
            success: function(layero, index){
                //var body = layer.getChildFrame('.ico-list', index);
                //console.log(layero, index);
            }
        });
    });
})

$.validator.setDefaults({
    submitHandler:function(){
        updateMenu();
    }
})

function validateEditForm(){
    $('#editMenuForm').validate({
        roles:{
            name:{
                required:true
            }
        },
        messages:{
            name:{
                required:'菜单名称不能为空'
            }
        }
    })
}
//修改菜单
function updateMenu(){
    $.ajax({
        url:prefix+'update',
        data:$('#editMenuForm').serialize(),
        type:'post',
        success:function(result){
            if(result.code=='0'){
                parent.layer.msg('修改菜单成功',{icon:'1'});
                parent.load();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }else {
                parent.layer.msg(result.msg,{icon:'2'});
            }
        }
    })
}
